﻿namespace uTorrentNAS.Utilities
{
    using Newtonsoft.Json;
    using System.IO;

    public class Serializer<T>
        where T : class
    {
        private readonly string _filename;

        public Serializer(string filename)
        {
            _filename = filename;
        }

        public void SerializeObject(T objectToSerialize)
        {
            File.WriteAllText(_filename, JsonConvert.SerializeObject(objectToSerialize));
        }

        public T DeserializeObject()
        {
            return JsonConvert.DeserializeObject<T>(File.ReadAllText(_filename));
        }
    }
}
